package ru.javadevelop.vegetarian.activities;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import ru.javadevelop.vegetarian.R;
import ru.javadevelop.vegetarian.common.ExtApplication;
import ru.javadevelop.vegetarian.controls.HeaderTitles;
import ru.javadevelop.vegetarian.fragments.HeaderFragment;
import ru.javadevelop.vegetarian.fragments.RecipesFragment;
import ru.javadevelop.vegetarian.model.Favorite;
import ru.javadevelop.vegetarian.model.Recipe;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: navff
 * Date: 24.02.13
 * Time: 16:12
 * To change this template use File | Settings | File Templates.
 */
public class FavoritesActivity extends Activity {
    LinearLayout root;
    HeaderFragment header_fragment;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_favorites);
        findControls();
        fillControls();
        setListeners();
    }
    //******************************************************************************************************************
    private void findControls()
    {
        root = (LinearLayout)findViewById(R.id.root);
        header_fragment = (HeaderFragment)getFragmentManager().findFragmentById(R.id.header_fragment);
    }
    //******************************************************************************************************************
    private void fillControls()
    {
        HeaderTitles headerTitles = new HeaderTitles(null, "", getString(R.string.favorites));
        header_fragment.setHeaderTitles(headerTitles);
        ArrayList<Favorite> favorites = Favorite.getAllForUser(ExtApplication.Session.googleAccount);
        if ( (favorites!=null) && (favorites.size()>0) )
        {
            ArrayList<Recipe> favoriteRecipes = new ArrayList<Recipe>();
            for (Favorite fav: favorites)
            {
                favoriteRecipes.add(Recipe.getById(fav.recipeId));
            }
            RecipesFragment recipesFragment = new RecipesFragment(favoriteRecipes);
            recipesFragment.setArguments(getIntent().getExtras());
            getFragmentManager().beginTransaction().add(R.id.root, recipesFragment).commit();
        }
    }
    //******************************************************************************************************************
    private void setListeners()
    {

    }
    //******************************************************************************************************************
    //******************************************************************************************************************
    //******************************************************************************************************************
    //******************************************************************************************************************
}
